{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name_j= ['jack', 'joe', 'jiaxin', 'jiaxin']\n",
      "['mike', 'marry', 'jack', 'joe', 'jiaxin', 'jiaxin']\n",
      "插入ethel的names ['mike', 'marry', 'ethel', 'jack', 'joe', 'jiaxin', 'jiaxin']\n",
      "4\n",
      "[100, 98, 93, 93, 92, 90, 83, 82]\n",
      "['ethel', 'jack', 'jiaxin', 'jiaxin', 'joe', 'marry', 'mike']\n",
      "[100, 98, 93, 93, 92, 90, 83, 82]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 列表 1.取值->1.index 取单个值 2.slice 切片一些值 还是一个列表\n",
    "# values是值即是列表里的值\n",
    "#name = \"alex,marry,jack\"\n",
    "#         0    1    2  3...\n",
    "#name_list = [\"alex\",\"marry\",\"jack\"]\n",
    "#              0       1     2       3...\n",
    "#print(name[0:4])\n",
    "#print(name[0])\n",
    "\n",
    "\n",
    "# * python中一切皆是对象 *\n",
    "# 2.列表增加\n",
    "  #2.1 append（）增加元素到list的末位 append（）的一般使用方法：新建列表会使用到\n",
    "\n",
    "  # 列表的方法会改变列表\n",
    "names_j = []\n",
    "names = [\"mike\",\"marry\",\"jack\",\"joe\",\"jiaxin\"]\n",
    "stu_grades = [92,93,98,82,83,90,100,93,]\n",
    "names.append(\"jiaxin\")\n",
    "for i in names:\n",
    "   if i[0] == \"j\":\n",
    "       names_j.append(i)\n",
    "print(\"name_j=\",names_j)\n",
    "print(names)\n",
    "\n",
    "  #2.2 insert() 插入元素\n",
    "names.insert(2,\"ethel\")\n",
    "print(\"插入ethel的names\",names)\n",
    "\n",
    "# 3.删除/移除\n",
    "#   #3.1 remove() 使用remove之前，应该先判断该元素是否存在该list当中\n",
    "# print(\"jiaxin\" in names)\n",
    "# names_user = input(\"输入删除内容：\")\n",
    "# while True:\n",
    "#     if names_user in names:\n",
    "#    else:\n",
    "#         break\n",
    "# names.remove(\"ethel\")\n",
    "# print(\"\",names)\n",
    "#stu_grades = [92,93,98,82,83,90,100]\n",
    "# 3.2 pop 删除 pop（）不填内容 对应记忆==》append（）删除末位\n",
    "#print(names)\n",
    "\n",
    "\n",
    "# 4. index()\n",
    "print(names.index(\"joe\"))\n",
    "\n",
    "#  5.sort 排序 默认从小到大排序 REVERSE= Fales(默认)小-大\n",
    "#REVERSE= True大-小\n",
    "stu_grades.sort(reverse=True)\n",
    "print(stu_grades)\n",
    "names.sort()# 首写字母从A-Z排序\n",
    "print(names)\n",
    "\n",
    "# 6.count 查看某元素出现的次数\n",
    "stu_grades.count(93)\n",
    "print(stu_grades)\n",
    "\n",
    "# 7.clear  清空列表\n",
    "# names.clear()\n",
    "# print(names)\n",
    "\n",
    "#  8. extend()是有顺序的，操作哪一个列表，那就要先写那个列表\n",
    "\n",
    "names.extend(names_j)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
